import Taro from '@tarojs/taro'

const baseUrl = 'http://localhost:5000'

const http = (options) => {
  //生成token
  const token = Taro.getStorageSync('token')
  if (!token && options.url !== '/login/land' && options.url !== '/upload' && options.url !== '/uploads') return

  return new Promise((resolve, reject) => {
    Taro.request({
      url: baseUrl + options.url,
      data: options.data || {},
      method: options.method || 'get',
      header: {
        'Content-type': 'application/json',
        'Authorization': `Bearer ${token}`
      },
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}


export default http